
import json
from django.conf import settings
import http.client

wxConfig = dict(WEIXIN_APP_ID=settings.WEIXIN_APP_ID, WEIXIN_APP_SECRET=settings.WEIXIN_APP_SECRET, WEIXIN_NOTIFY_URL=settings.WEIXIN_PAY_NOTIFY_URL, WEIXIN_MCH_KEY=settings.WEIXIN_MCH_KEY, WEIXIN_MCH_ID=settings.WEIXIN_MCH_ID)

def get_access_token(code):
  path = "/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code" % (settings.WX_LOGIN_APPID, settings.WX_LOGIN_APPSECRET, code)
  conn = http.client.HTTPSConnection("api.weixin.qq.com")
  conn.request("GET", path)
  ret = conn.getresponse().read().decode('utf-8')
  print(ret, json.loads(ret))
  return json.loads(ret)